Compute degree-days for heating and cooling

This notebook shows how to compute degree-days for heating and/or cooling from the ambient temperature. We compute degree-days with different base temperatures. This is a very useful input for eg. multivarible analyses, like this one.

Imports


In [ ]:
import opengrid as og
import pandas as pd

In [ ]:
plt = og.plot_style()

Prepare dataset


In [ ]:
# A dataset with hourly weather variables for Brussels (2016) is included in OpenGrid.  
# Note that the data contains also the last week of 2015. 
# This is required in order for the degree-days computation to work for the first days of January. 
dfw = og.datasets.get('weather_2016_hour')

In [ ]:
# We only need temperature
temp = dfw.temperature

Degree-days work on daily data, so we want to resample our dataset to the daily mean.


In [ ]:
temp = temp.resample('D').mean()

In [ ]:
fig = temp.plot()

Compute degree days


In [ ]:
# set base temperatures
heating_base_temperatures = range(8, 18, 2) # 8, 10, 12, 14, 16, 18
cooling_base_temperatures = range(16, 26, 2) # 16, 18, ...

In [ ]:
# compute degree days for each of the base temperatures and return them in a dataframe called DD
DD = og.library.weather.compute_degree_days(
    ts=temp,
    heating_base_temperatures=heating_base_temperatures,
    cooling_base_temperatures=cooling_base_temperatures
)
# restrict the dataframe to 2016
DD = DD.loc['2016']

Plot weekly degree days

We resample the daily degree-days to weekly sums and plot the results.


In [ ]:
DD_weekly = DD.resample('W').sum()

In [ ]:
fig = DD_weekly.filter(like='HDD').plot()
fig.set_title('Weekly heating degree-days with different base temperatures')
plt.show()

In [ ]:
fig = DD_weekly.filter(like='CDD').plot()
fig.set_title('Weekly cooling degree-days with different base temperatures')
plt.show()

In [ ]: